package Controller;

import javax.swing.JFrame;
import javax.swing.JPanel;

import Controller.Client;
import Entity.Order;

import GUI.FrameSystem;
import GUI.MainGui;
import GUI.OneTimeOrderInAdvanceWin;
import GUI.SubscriptionOrderGui;
import GUI.ViewOrCancelOrders;

/**
 * this is the controller for one time order on advance. it will mainly show the orders in advance window.
 * @author Or Marx
 *
 */
public class OneTimeOrderInAdvance {
	/**
	 * is the function that will run the get order GUI.
	 */
	public void getOrder()
	{
		JFrame frame=FrameSystem.getFrame();
		OneTimeOrderInAdvanceWin subOrder=new OneTimeOrderInAdvanceWin();
		subOrder.setLastPanel((JPanel)frame.getContentPane());
		subOrder.setFrame(frame);
		frame.setContentPane(subOrder);
		frame.setVisible(true);
	}
	/**
	 * is the function that will run the view order GUI.
	 */
	public void viewOrder()
	{
		Order orders []=Client.getOrders();
		int n=0;
		for (int i=0; i<orders.length; i++)
			if (orders[i].getCustomerID().equals(Client.getLoggedIn()))
				n++;
		Order ordersById[]=new Order[n];
		int j=0;
		for (int i=0; i<orders.length; i++)
			if (orders[i].getCustomerID().equals(Client.getLoggedIn()))
			{
				ordersById[j]=orders[i];
				j++;
			}
		JFrame frame=FrameSystem.getFrame();
		ViewOrCancelOrders subOrder=new ViewOrCancelOrders(ordersById);
		subOrder.setLastPanel((JPanel)frame.getContentPane());
		subOrder.setFrame(frame);
		frame.setContentPane(subOrder);
		frame.setVisible(true);
		
	}

}
